package com.xinzhidi.web.dataset.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.web.dataset.domain.dto.DataSetDto;
import com.xinzhidi.web.dataset.domain.po.DataSetPo;
import com.xinzhidi.web.dataset.service.DataSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 初始设置Controller
 *
 * @author cx
 * @date 2023-06-27
 */
@RestController
@Api(tags = "初始设置")
@RequestMapping("/dataset")
@RequiredArgsConstructor
public class DataSetController extends BaseController {

    private final DataSetService dataSetService;

    @ApiOperation("查询初始设置详情")
    @PostMapping("/getDataSetInfo")
    public AjaxResult getDataSetInfo(@Validated @RequestBody DataSetPo po) {
        return AjaxResult.success(dataSetService.getDataSetInfo(po));
    }

    @ApiOperation("新增初始设置")
    @PreAuthorize("@ss.hasPermi('dataset:dataset:add')")
    @Log(title = "新增初始设置", businessType = BusinessType.INSERT)
    @PostMapping("addDataSet")
    public AjaxResult addDataSet(@Validated @RequestBody DataSetDto dto) {
        return toAjax(dataSetService.insertDataSet(dto));
    }

    @ApiOperation("修改初始设置")
    @PreAuthorize("@ss.hasPermi('dataset:dataset:edit')")
    @Log(title = "修改初始设置", businessType = BusinessType.UPDATE)
    @PostMapping("editDataSet")
    public AjaxResult editDataSet(@Validated @RequestBody DataSetDto dto) {
        return toAjax(dataSetService.updateDataSet(dto));
    }

}
